home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / cube_v1.zip / CUBE1.C < prev    next >
Text File  |  1993-06-13  |  27KB  |  979 lines

  1. /*******************************************************************
  2.  *  CUBE1.C by  Hubert Lin & Andrew Lee                            *
  3.  *              Mechanical Eng. of National Central University     *
  4.  *                    Started  4-27-1993       *
  5.  *                    Finished 6-15-1993       *
  6.  *    Copyright(C) 1993        All Rights Reserved       *
  7.  *******************************************************************/
  8.  
  9. #define VERSION     "Version 1.0"
  10.  
  11. #define F            0   /* Front  face */
  12. #define R            1   /* Right  face */
  13. #define T            2   /* Top    face */
  14. #define H            3   /* Bottom face */
  15. #define L            4   /* Left   face */
  16. #define B            5   /* beHind face */
  17.  
  18. #define RR           0   /* Red      */
  19. #define OO           1   /* Orange   */
  20. #define GG           2   /* Green    */
  21. #define BB           3   /* Blue     */
  22. #define YY           4   /* Yellow   */
  23. #define WW           5   /* White    */
  24.  
  25. #define SRIMN        8   /* number of small_rim */
  26. #define BRIMN       12   /* number of big_rim   */
  27.  
  28. #define CW          -1   /* clockwise */
  29. #define CCW         -2   /* counterclockwise */
  30.  
  31. #define ESC         27   /* key code of Esc */
  32. #define F1          59
  33. #define F2          60
  34. #define F3          61
  35. #define F4          62
  36. #define F5          63
  37. #define F6          64
  38.  
  39. #define ON           1
  40. #define OFF          0
  41.  
  42. #include <dos.h>
  43. #include <alloc.h>
  44. #include <ctype.h>
  45. #include <conio.h>
  46. #include <stdio.h>
  47. #include <stdlib.h>
  48. #include <graphics.h>
  49. #include "mouse.h"
  50.  
  51. void body( char );
  52. char getmousech( MOUSE * );
  53. void to_graphic_mode( void );
  54. void initialize( void );
  55. void handle( char );
  56. void faceCW( char );
  57. void faceCCW( char );
  58. int  cond( char );
  59. void reassignfacestruct( char );
  60. void showcube( void );
  61. void cube_rotate( char , int );
  62. void savegame( void );
  63. void loadgame( void );
  64. void soundswitch( void );
  65. void speedswitch( void );
  66. void word( void );
  67. void title( void );
  68. void draw_win( void );
  69. void sink( int , int , int , int , int );
  70. void mem_error( void );
  71. void file_error( char * );
  72. void show_version( int , int , int );
  73. void palette( int );
  74. void shell( void );
  75. void clr_kb_buff( void );
  76. void sinkkey( char );
  77. void help( void );
  78. void message( int , char * );
  79. void cubesound( void );
  80.  
  81. int first=0;        /* check if it is first time to draw the cube     */
  82. int speed=30;        /* the rotation speed of the cube          */
  83.  
  84. int speeddata[] = {10, 30, 50};
  85.             /* they are "Fast", "Normal", and "Slow".    */
  86.  
  87. int speedcontrol = 1;    /* the controler of speeddata[]            */
  88. MOUSE mouse;        /* the structure of the cursor of the mouse    */
  89. int soundflag = ON;    /* the flag of sound ON or OFF            */
  90. int mu_install =OFF;    /* the flag of use_mouse or not_use_mouse    */
  91. int sq[49];        /* the color of the 48 squares, begins at sq[1]    */
  92.  
  93. int condition[] =  {RR, BB, YY, OO, GG, WW};
  94.     /* they are  F,  R,  T,  H,  L,  B ,respectively*/
  95.  
  96. int now=0, next=0;
  97. int color[] ={ GREEN , LIGHTRED ,  RED  , DARKGRAY , LIGHTGRAY , WHITE };
  98.              /* RED  ,    BROWN , GREEN ,     BLUE ,    YELLOW , WHITE */
  99.  
  100. /* the structure of the 6 faces */
  101. struct one_face
  102. {
  103.     int *srim[SRIMN+1];      /* begins at srim[1]    */
  104.     int *brim[BRIMN+1];      /* begins at brim[1]    */
  105. } face[] =
  106. {
  107.     {    NULL ,  &sq[1] ,  &sq[2] ,  &sq[3] ,  &sq[4] ,  &sq[5] ,  &sq[6] ,
  108.        &sq[7] ,  &sq[8] ,    NULL , &sq[39] , &sq[38] , &sq[37] , &sq[25] ,
  109.       &sq[32] , &sq[31] , &sq[47] , &sq[46] , &sq[45] , &sq[21] , &sq[20] ,
  110.       &sq[19] } ,
  111.  
  112.     {    NULL ,  &sq[9] , &sq[10] , &sq[11] , &sq[12] , &sq[13] , &sq[14] ,
  113.       &sq[15] , &sq[16] ,    NULL , &sq[35] , &sq[34] , &sq[33] , &sq[17] ,
  114.       &sq[24] , &sq[23] , &sq[43] , &sq[42] , &sq[41] , &sq[29] , &sq[28] ,
  115.       &sq[27] } ,
  116.  
  117.     {    NULL , &sq[17] , &sq[18] , &sq[19] , &sq[20] , &sq[21] , &sq[22] ,
  118.       &sq[23] , &sq[24] ,    NULL , &sq[33] , &sq[40] , &sq[39] ,  &sq[1] ,
  119.        &sq[8] ,  &sq[7] , &sq[45] , &sq[44] , &sq[43] , &sq[13] , &sq[12] ,
  120.       &sq[11] } ,
  121.  
  122.     {    NULL , &sq[25] , &sq[26] , &sq[27] , &sq[28] , &sq[29] , &sq[30] ,
  123.       &sq[31] , &sq[32] ,    NULL , &sq[37] , &sq[36] , &sq[35] ,  &sq[9] ,
  124.       &sq[16] , &sq[15] , &sq[41] , &sq[48] , &sq[47] ,  &sq[5] ,  &sq[4] ,
  125.        &sq[3] } ,
  126.  
  127.     {    NULL , &sq[33] , &sq[34] , &sq[35] , &sq[36] , &sq[37] , &sq[38] ,
  128.       &sq[39] , &sq[40] ,    NULL , &sq[11] , &sq[10] ,  &sq[9] , &sq[27] ,
  129.       &sq[26] , &sq[25] ,  &sq[3] ,  &sq[2] ,  &sq[1] , &sq[19] , &sq[18] ,
  130.       &sq[17] } ,
  131.  
  132.     {    NULL , &sq[41] , &sq[42] , &sq[43] , &sq[44] , &sq[45] , &sq[46] ,
  133.       &sq[47] , &sq[48] ,    NULL , &sq[15] , &sq[14] , &sq[13] , &sq[23] ,
  134.       &sq[22] , &sq[21] ,  &sq[7] ,  &sq[6] ,  &sq[5] , &sq[31] , &sq[30] ,
  135.       &sq[29] }
  136. };
  137.  
  138. struct condition_data
  139. {
  140.     int face[6];             /* face F , R , T , H , L , B */
  141.     int lefttop[3];          /* face F , R , T */
  142.     int cw[3][2];            /* rotate about x , y , z */
  143.     int ccw[3][2];           /* rotate about x , y , z */
  144. } conddata[] =
  145. {
  146.      {RR,BB,YY,OO,GG,WW, 1,1,1,  WW,BB, RR,YY, BB,OO,  YY,BB, RR,WW, GG,RR},
  147.      {RR,WW,BB,OO,YY,GG, 3,7,3,  GG,WW, RR,BB, WW,OO,  BB,WW, RR,GG, YY,RR},
  148.      {RR,GG,WW,OO,BB,YY, 5,5,1,  YY,GG, RR,WW, GG,OO,  WW,GG, RR,YY, BB,RR},
  149.      {RR,YY,GG,OO,WW,BB, 7,7,7,  BB,YY, RR,GG, YY,OO,  GG,YY, RR,BB, WW,RR},
  150.  
  151.      {OO,GG,YY,RR,BB,WW, 1,1,5,  WW,GG, OO,YY, GG,RR,  YY,GG, OO,WW, BB,OO},
  152.      {OO,WW,GG,RR,YY,BB, 3,3,3,  BB,WW, OO,GG, WW,RR,  GG,WW, OO,BB, YY,OO},
  153.      {OO,BB,WW,RR,GG,YY, 5,5,5,  YY,BB, OO,WW, BB,RR,  WW,BB, OO,YY, GG,OO},
  154.      {OO,YY,BB,RR,WW,GG, 7,3,7,  GG,YY, OO,BB, YY,RR,  BB,YY, OO,GG, WW,OO},
  155.  
  156.      {GG,YY,OO,BB,WW,RR, 7,1,7,  RR,YY, GG,OO, YY,BB,  OO,YY, GG,RR, WW,GG},
  157.      {GG,RR,YY,BB,OO,WW, 1,1,3,  WW,RR, GG,YY, RR,BB,  YY,RR, GG,WW, OO,GG},
  158.      {GG,WW,RR,BB,YY,OO, 3,5,3,  OO,WW, GG,RR, WW,BB,  RR,WW, GG,OO, YY,GG},
  159.      {GG,OO,WW,BB,RR,YY, 5,5,7,  YY,OO, GG,WW, OO,BB,  WW,OO, GG,YY, RR,GG},
  160.  
  161.      {BB,OO,YY,GG,RR,WW, 1,1,7,  WW,OO, BB,YY, OO,GG,  YY,OO, BB,WW, RR,BB},
  162.      {BB,WW,OO,GG,YY,RR, 3,1,3,  RR,WW, BB,OO, WW,GG,  OO,WW, BB,RR, YY,BB},
  163.      {BB,RR,WW,GG,OO,YY, 5,5,3,  YY,RR, BB,WW, RR,GG,  WW,RR, BB,YY, OO,BB},
  164.      {BB,YY,RR,GG,WW,OO, 7,5,7,  OO,YY, BB,RR, YY,GG,  OO,YY, BB,OO, WW,BB},
  165.  
  166.      {YY,BB,OO,WW,GG,RR, 1,3,5,  RR,BB, YY,OO, BB,WW,  OO,BB, YY,RR, GG,YY},
  167.      {YY,RR,BB,WW,OO,GG, 3,3,5,  GG,RR, YY,BB, RR,WW,  BB,RR, YY,GG, OO,YY},
  168.      {YY,GG,RR,WW,BB,OO, 5,3,5,  OO,GG, YY,RR, GG,WW,  RR,GG, YY,OO, BB,YY},
  169.      {YY,OO,GG,WW,RR,BB, 7,3,5,  BB,OO, YY,GG, OO,WW,  GG,OO, YY,BB, RR,YY},
  170.  
  171.      {WW,GG,OO,YY,BB,RR, 1,7,1,  RR,GG, WW,OO, GG,YY,  OO,GG, WW,RR, BB,WW},
  172.      {WW,RR,GG,YY,OO,BB, 3,7,1,  BB,RR, WW,GG, RR,YY,  GG,RR, WW,BB, OO,WW},
  173.      {WW,BB,RR,YY,GG,OO, 5,7,1,  OO,BB, WW,RR, BB,YY,  RR,BB, WW,OO, GG,WW},
  174.      {WW,OO,BB,YY,RR,GG, 7,7,1,  GG,OO, WW,BB, OO,YY,  BB,OO, WW,GG, RR,WW}
  175. };
  176.  
  177. /* the initial color of the 3 visible faces ( Front, Right, Top )    */
  178. struct vfacedata
  179. {
  180.     int color[8];
  181. } vface[] =
  182. {
  183.     { GREEN , GREEN , GREEN , GREEN , GREEN , GREEN , GREEN , GREEN } ,
  184.     {  DARKGRAY ,  DARKGRAY ,  DARKGRAY ,  DARKGRAY ,  DARKGRAY ,  DARKGRAY ,
  185.        DARKGRAY ,  DARKGRAY } ,
  186.     { LIGHTGRAY , LIGHTGRAY , LIGHTGRAY , LIGHTGRAY , LIGHTGRAY , LIGHTGRAY ,
  187.       LIGHTGRAY , LIGHTGRAY }
  188. };
  189.  
  190. /* defines the mouse clickable areas and the corresponding keys */
  191. struct mu_click
  192. {
  193.         int cl, ct, cr, cb;     /* left, top, right, bottom points of the area */
  194.     char key;        /* the corresponding keys of the area */
  195. } def_click[]=
  196. {
  197.     {  18+(65+1)*0 , 253 ,  18+(65+1)*0+64 , 253+44 , 'f' },
  198.     {  18+(65+1)*1 , 253 ,  18+(65+1)*1+64 , 253+44 , 'r' },
  199.     {  18+(65+1)*2 , 253 ,  18+(65+1)*2+64 , 253+44 , 't' },
  200.     {  18+(65+1)*3 , 253 ,  18+(65+1)*3+64 , 253+44 , 'l' },
  201.     {  18+(65+1)*4 , 253 ,  18+(65+1)*4+64 , 253+44 , 'b' },
  202.     {  18+(65+1)*5 , 253 ,  18+(65+1)*5+64 , 253+44 , 'h' },
  203.     { 426+(65+1)*0 , 253 , 426+(65+1)*0+64 , 253+44 , 'x' },
  204.     { 426+(65+1)*1 , 253 , 426+(65+1)*1+64 , 253+44 , 'z' },
  205.     { 426+(65+1)*2 , 253 , 426+(65+1)*2+64 , 253+44 , 'y' }